const http = require('http')

const app = http.createServer((req, res) => { 
    res.setHeader("Access-Control-Allow-Origin","*");
    res.writeHead(200,{"Content-type" : "text/plain;charset=utf-8"});
    if (req.method === 'GET') {
        if (req.url === '/name') {
            setTimeout(() => {
                res.end('hello node')
            }, 0)
        }
    } else if (req.method === 'POST') { 
        let str = ''
        req.on('data', (data) => { 
            str += data
        })
        req.on('end', () => { 
            setTimeout(() => { 
                res.end(str)
            },1500)
        })
    }
})

app.listen(666, () => { 
    console.log('Server is running on port 666')
})